package com.ranjiaqi.jdbc;

import java.sql.*;

/**
 * @ClassName textjdbc
 * @Description TODO
 * @Author hp
 * @Date 2021/7/12 8:53
 * @Version 1.0
 **/
public class textjdbc {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/testjdbc";
        String username = "root";
        String password = "1234";
        Connection connection = DriverManager.getConnection(url,username,password);
        String sql = "select * from user";
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()){
            System.out.println(resultSet.getObject(1));
            System.out.println(resultSet.getObject(2));
            System.out.println(resultSet.getObject(3));
            System.out.println(resultSet.getObject(4));

        }
        if (resultSet != null){
            resultSet.close();
        }
        if(statement != null){
            statement.close();
        }
        if(connection != null){
            connection.close();
        }
    }


}
